<?php
require_once("includes/dbfunctions.php");



function valid_email($str)
{
    return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}




if(!empty($_POST['Email']) && !empty($_POST['First']) && !empty($_POST['Last']) && !empty($_POST['Zip']) && !empty($_POST['Firstp']) && !empty($_POST['Lastp']) && !empty($_POST['Password'])
    && !empty($_POST['Confirm_Password']))
{



    $Phone = $_POST['Zip'] .$_POST['Firstp'] .$_POST['Lastp'];
    $Office = $_POST['Office'];


    if(!valid_email($_POST['Email']))
    {
        $error[] = "Invalid Email";
    }
    else
    {
        $Email = mysql_real_escape_string($_POST['Email']);
    }

    if(strlen($_POST['Password']) <= 5)
    {
        $error[] = "Invalid Password";

    }

    if(($_POST['Password'] != $_POST['Confirm_Password']))
    {
        $error[] = "Invalid Password";
    }
    else
    {
        $Password = mysql_real_escape_string($_POST['Password']);
        $Password = md5($Password);
    }

    if(!ctype_alpha($_POST['First']))
    {
        $error[] = "Invalid First";
    }
    else
    {
       $First = mysql_real_escape_string($_POST['First']);
    }

    if(!ctype_alpha($_POST['Last']))
    {
      $error[] = "Invalid Last";
    }
    else
    {
       $Last = mysql_real_escape_string($_POST['Last']);
    }

    if(!ctype_digit($Phone))
    {
        $error[] = "Invalid Phone";
    }

    
    
    
}
else
{
    require_once("registration.php");
    exit;
}


if(is_array($error))
{
 require_once("registration.php");
 exit;
}
else
{
    enterUser($Email,$First,$Last,$Office,$Phone,$Password);
    require_once("welcome.php");
    exit;

}

?>